package com.db.ionio.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class FileIOCopier {

    public static void main(String[] args) throws Exception {

        if (args.length < 2) {
            System.out.format("Usage: %s <source> <destination>%n", FileIOCopier.class.getName());
            System.exit(1);
        }

        final String src = args[0];
        final String dst = args[1];

        long start = System.nanoTime();

        try (
                FileInputStream in = new FileInputStream(new File(src));
                FileOutputStream out = new FileOutputStream(new File(dst));
        ) {
            final int bufferSize = 32 * 1024;
            final byte[] buffer = new byte[bufferSize];
            int currentBytesRead;
            while ((currentBytesRead = in.read(buffer)) != -1)
                out.write(buffer, 0, currentBytesRead);
        }

        long time = System.nanoTime() - start;
        System.out.println(time);
    }


}
